这里是从DataTable创建图表的示例代码。
Visual Basic |
拷贝代码
|
---|---|
Private _dataSet As DataSet Private Sub Window_Loaded(ByVal sender As Object, ByVal e As RoutedEventArgs) ' 创建连接并填充数据集 Dim mdbFile As String = "c:\db\nwind.mdb" Dim connString As String = String.Format("Provider=Microsoft.Jet.OLEDB.4.0; Data Source={0}", mdbFile) Dim conn As New OleDbConnection(connString) Dim adapter As New OleDbDataAdapter("SELECT TOP 10 ProductName, UnitPrice FROM Products " & vbCr & vbLf & " ORDER BY UnitPrice;", conn) _dataSet = New DataSet() adapter.Fill(_dataSet, "Products") ' 将数据表列设置为图表数据的数据源 c1Chart1.Data.ItemsSource = _dataSet.Tables("Products").Rows End Sub |
C# |
拷贝代码
|
---|---|
DataSet _dataSet; private void Window_Loaded(object sender, RoutedEventArgs e) { // 创建连接并填充数据集 string mdbFile = @"c:\db\nwind.mdb"; string connString = string.Format( "Provider=Microsoft.Jet.OLEDB.4.0; Data Source={0}", mdbFile); OleDbConnection conn = new OleDbConnection(connString); OleDbDataAdapter adapter = new OleDbDataAdapter( @"SELECT TOP 10 ProductName, UnitPrice FROM Products ORDER BY UnitPrice;", conn); _dataSet = new DataSet(); adapter.Fill(_dataSet, "Products"); // 将数据表列设置为图表数据的数据源 c1Chart1.Data.ItemsSource = _dataSet.Tables["Products"].Rows; } |
XAML
XAML |
拷贝代码
|
---|---|
<c1chart:C1Chart.Data> <c1chart:ChartData ItemNameBinding="{Binding Path=[ProductName]}"> <c1chart:DataSeries ValueBinding="{Binding Path=[UnitPrice]}"/> </c1chart:ChartData> </c1chart:C1Chart.Data> |